﻿
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;

using SmalShop.Model;

namespace SmallShop.Dal
{
    internal class ShopDbContext: DbContext
    {
        public ShopDbContext(string nameOrConnectionString) : base(nameOrConnectionString)
        {

        }

        public DbSet<ProductModel> Products { get; set; }

        public DbSet<CategoryModel> Categroys { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            
            var p = modelBuilder.Entity<ProductModel>().ToTable("Product");
            p.HasKey(it => it.Id).Property(it => it.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            modelBuilder.Entity<CategoryModel>().ToTable("Category").HasKey(it => it.Id).Property(it=>it.Id).IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            modelBuilder.Entity<ManagerModel>().ToTable("Manager").HasKey(it => it.Id).Property(it => it.Id).IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            modelBuilder.Entity<BannerModel>().ToTable("Banner").HasKey(it => it.Id).Property(it => it.Id).IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            base.OnModelCreating(modelBuilder);

        }
    }
}
